package freemind.controller;

import java.io.Serializable;
import java.util.ArrayList;

import freemind.controller.AtributoEnegModulo;

public class NodeBean implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private int virtualId;
	private int id;
	private int idParent;
	private int idRaiz;
	private int type;
	private String text;
	private Boolean left;
	private int link;
	private String linkString;
	
	private int usuarioId;
		
	private int copia_id;
	private boolean _isCreated=false;
	private boolean _hasChanged = false;

	private ArrayList<AtributoEnegModulo> extras;
		
	
	public void setUID(int uid){
		this.usuarioId = uid;
	}
	
	public int getUID(){
		return this.usuarioId;
	}	
	
	public void newNode(){
		_isCreated = true;
	}
	
	public void toCreate(){
		_isCreated = false;
	}
	
	public void hasChanged(){
		this._hasChanged = true;
	}
	
	public void hasSaved(){
		this._hasChanged = false;
	}
	
	public boolean isVirtual(){
		return this.id==0;
	}
	
	public boolean isChanged(){
		return this._hasChanged;
	}
	
	public boolean isCreated(){
		return _isCreated;
	}
	
	public void setVirtualId(int virtualId){
		this.virtualId = virtualId;
	}
	
	public int getVirtualId(){
		return this.virtualId;
	}
	
	public void setLinkString(String l){
		this.linkString = l;
	}
	
	public String getLinkString(){
		return this.linkString;
	}
	
	public int getLink() {
		return link;
	}

	public void setLink(int link) {
		this.link = link;
		
		if( link!= 0){
			this.setLinkString( "%%link_interno%%"+link );
		}		
		else{
			this.setLinkString(null);
		}
	}
	
	
	public int getId() {
		if( id==0 ){
			return virtualId;
		}
		else{
			return id;	
		}
		
	}

	public int getIdParent() {
		return idParent;
	}

	public void setIdParent(int idParent) {
		this.idParent = idParent;
	}

	public int getIdRaiz() {
		return idRaiz;
	}

	public void setIdRaiz(int idRaiz) {
		this.idRaiz = idRaiz;
	}
	
	public int getTipo() {
		return type;
	}

	public void setTipo(int tipo) {
		this.type = tipo;
	}

	public String getTexto() {
		return text;
	}

	public void setTexto(String texto) {
		this.text = texto;
	}

	public Boolean getLeft() {
		return left;
	}

	public void setLeft(Boolean left) {
		this.left = left;
	}

	public void setId(int id) {
		this.id = id;
	}
	
	public int getCopiaId(){
		return this.copia_id;
	}
	
	public void setCopiaId(int id){
		this.copia_id = id;
	}
		
	public NodeBean(){
		this(0,0,0,0,true,1,"Novo no",0,0);
	}
	
	public NodeBean(int virtualId,int id, int idParent, int idRaiz, Boolean left,int type, String text,int link,int copia_id){
		this.setVirtualId(virtualId);
		this.setId(id);
		this.setIdParent(idParent);
		this.setIdRaiz( idRaiz );
		this.setLeft(left);
		this.setTipo( type );
		this.setTexto( text );		
		this.setLink( link );
		this.setCopiaId( copia_id );
		
	}
	
	public NodeBean(int virtualId,int idParent,int idRaiz, int type, String text,Boolean left, int link,int copia_id){
		this(virtualId,0,idParent,idRaiz,left,type,text,link,copia_id);
	}	
	
	public boolean isRoot(){
		return idParent==0;
	}
	
	public void addAtributoExtra(AtributoEnegModulo attr){
		this.extras.add( attr );
	}	
	
	public ArrayList<AtributoEnegModulo> getAtributosExtras() {
		return this.extras;
	}
	
	public void clearAtributosExtras(){
		this.extras.clear();
	}	
		
	
	
}
